/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShEquipmentDevIpcDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShEquipmentDevIpcService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShEquipmentDevIpc;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShEquipmentDevIpcService 实现类
 * 
 * @author KongXiangyu
 * @since 2015-11-23
 */
@Service("shEquipmentDevIpcService")
public class ShEquipmentDevIpcServiceImpl extends BaseServiceImpl<ShEquipmentDevIpc, Long> implements ShEquipmentDevIpcService {

    @Resource
    private ShEquipmentDevIpcDao shEquipmentDevIpcDao;

    public BaseDao<ShEquipmentDevIpc, Long> getDao() {
        return shEquipmentDevIpcDao;
    }

    @Override
    public DataGrid queryDataGrid(ShEquipmentDevIpc devIpc, PageHelper page) {
        DataGrid dataGrid = new DataGrid();
        long totalCount = shEquipmentDevIpcDao.selectEntryListCount(devIpc);
        if (!StringUtils.isBlank(page.getOrder())) {
            devIpc.setOrderFieldType(page.getOrder());
        }
        if (!StringUtils.isBlank(page.getSort())) {
            devIpc.setOrderField(page.getSort());
        }
        dataGrid.setTotal(totalCount);
        int startIndex = (page.getPage() - 1) * page.getRows();
        int endIndex = page.getPage() * page.getRows();
        if (totalCount > 0 && totalCount > startIndex) {
            devIpc.setStartIndex(startIndex);
            devIpc.setEndIndex(endIndex);
            List<ShEquipmentDevIpc> ipcs = shEquipmentDevIpcDao.selectList(devIpc);
            dataGrid.setRows(ipcs);
        }
        return dataGrid;
    }

    @Override
    public void updateByResidenceId(ShEquipmentDevIpc shEquipmentDevIpc) {
        shEquipmentDevIpcDao.updateByResidenceId(shEquipmentDevIpc);
    }

}